package com.aabte.design2.behavioral.strategy;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/5/4
 */
public class Application {

    private static final List<String> OPERATIONS = Lists.newArrayList(
            "add", "mul", "sub", "div"
    );

    public static void main(String[] args) {
        Strategy strategy = getStrategy(OPERATIONS.get(ThreadLocalRandom.current().nextInt(4)));

        Context context = new Context();
        context.setStrategy(strategy);

        int rs = context.executeStrategy(1, 2);
        System.out.println("rs = " + rs);
    }

    private static Strategy getStrategy(String operation) {

        if ("add".equals(operation)) {
            return new ConcreteStrategyAdd();
        } else if ("mul".equals(operation)) {
            return new ConcreteStrategyMultiply();
        } else if ("sub".equals(operation)) {
            return new ConcreteStrategySubtract();
        } else if ("div".equals(operation)) {
            return new ConcreteStrategyDivision();
        }

        return null;
    }

}
